package com.yb.guigu.pick.upload.controller;

import com.yb.guigu.pick.upload.service.IUploadService;
import com.yb.guigu.pick.core.bean.GuiguResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/2 14:35
 * FileName: UploadController
 * Description:
 */

@RestController
@Slf4j
public class UploadController {


    @Autowired
    IUploadService uploadService;

    @PostMapping("/upload")
    public GuiguResult upload(@RequestPart("file") MultipartFile file) throws IOException {
        Long companyId=123L;

        return uploadService.upload(file);
    }


    @PostMapping("/upload/chunk/{fileMD5}/{currentIndex}")
    public GuiguResult uploadChunk(@PathVariable String fileMD5,@PathVariable Integer currentIndex,@RequestPart MultipartFile chunk){
        return uploadService.uploadChunk(fileMD5,currentIndex,chunk);
    }

    @PostMapping("/upload/chunk/{chunkMd5}")
    public GuiguResult uploadChunkByChunkMd5(@PathVariable String chunkMd5,@RequestPart MultipartFile chunk){
        return uploadService.uploadChunkByChunkMd5(chunkMd5,chunk);
    }



    @GetMapping("/upload/mergeChunk/{fileMD5}/{numOfChunk}")
    public GuiguResult mergeChunk(@PathVariable String fileMD5,@PathVariable Integer numOfChunk,@RequestParam String suffix){
        return uploadService.mergeChunk(fileMD5,numOfChunk,suffix);
    }



    @PostMapping("/upload/mergeChunk/{fileMD5}")
    public GuiguResult mergeChunk(@RequestBody List<String> chunkMD5s,@PathVariable String fileMD5,@RequestParam String suffix){
        return uploadService.mergeChunk(chunkMD5s,fileMD5, suffix);
    }
    @PostMapping("/md5")
    public GuiguResult md5(@RequestPart("file") MultipartFile file){
        return uploadService.md5(file);
    }
}
